package com.yloveg.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yloveg.common.FreemarkUtil.YesOrNo;
import com.yloveg.dao.ShopCartMapper;
import com.yloveg.dao.ShopInfoMapper;
import com.yloveg.entity.ShopCart;
import com.yloveg.entity.ShopCartExtend;
import com.yloveg.entity.ShopInfoExtend;
import com.yloveg.service.ShopCartService;


@Service
public class ShopCartServiceImpl implements ShopCartService {
	
    @Autowired
    private ShopCartMapper shopCartMapper;
    
    @Autowired
    private ShopInfoMapper shopInfoMapper;

	@Override
	public List<ShopCart> selectByTerm(ShopCart record) {
		// TODO Auto-generated method stub
		return shopCartMapper.selectByTerm(record);
	}

	@Override
	public int insertShopCart(ShopCart record) {
		// TODO Auto-generated method stub
		record.setCreateTime(new Date());
		record.setState(1);
		return shopCartMapper.insert(record);
	}

	@Override
	public int updateByPrimaryKeySelective(ShopCart record) {
		// TODO Auto-generated method stub
		return shopCartMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int deleteByTerm(ShopCart record) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public ShopCart selectOne(ShopCart record) {
		// TODO Auto-generated method stub
		List<ShopCart> list = shopCartMapper.selectByTerm(record);
		if(list.size()>0){
			return list.get(0);
		}else{
			return null;
		}
		
	}

	@Override
	public List<ShopInfoExtend> selectCartWidthShop(Map<String, Object> map) {
		// TODO Auto-generated method stub
		List<ShopInfoExtend> resultList = shopInfoMapper.selectShopByCart(map);
		Map<String,Object> parMap = new HashMap<String, Object>();
		parMap.put("cartStatus", map.get("cartStatus"));
		for (ShopInfoExtend shopInfoExtend : resultList) {
			parMap.put("shopId", shopInfoExtend.getId());
			parMap.put("userId", map.get("userId"));
			shopInfoExtend.setShopCart(shopCartMapper.selectExtendByTerm(parMap));
		}
		return resultList;
	}

	@Override
	public List<ShopCartExtend> selectExtendByTerm(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return shopCartMapper.selectExtendByTerm(map);
	}
	
	

}
